// basicnpc.txt
// A very simple, naive text. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Number of state when talked to. Plays default text if 0.

begincreaturescript;

variables;

short i,target;
short met_pc = 0;
short mess1 = 0,mess2 = 0;

body;

beginstate INIT_STATE;
	set_level(ME,7);
	change_max_health(ME,60);
	set_boss_level(ME,2);
	set_name(ME,"Koski");
	break;

beginstate DEAD_STATE;
	sf(10,1,1);
break;

beginstate START_STATE; 
	if (who_shot_me() >= 0) {
		met_pc = 1;
		sf(10,8,0);
		}
	if (met_pc == 0) {
		if (party_dist_to_nav(1) <= 6) {
			met_pc = 1;
			talk_no_exit(50);
			}
		end();
		}
	if ((met_pc > 0) && (gf(10,8) > 0))
		end();
	
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	
	if (my_dist_from_start() >= 6) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}


	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	
	if ((mess1 == 0) && (get_health(ME) < get_max_health(ME))) {
		mess1 = 1;
		sf(10,10,1);
		set_act_at_dist(14,1);
		set_act_at_dist(15,1);
		set_act_at_dist(16,1);
		set_act_at_dist(17,1);
		
		if (dist_to_pc() <= 10)
			begIn_talk_mode(60);
			else begIn_talk_mode(61);
		}
	if ((mess1 > 0) && (mess2 == 0) && (get_health(ME) < get_max_health(ME) / 2)) {
		mess2 = 1;
		sf(10,11,1);
		set_act_at_dist(18,1);
		set_act_at_dist(19,1);
		set_act_at_dist(20,1);
		set_act_at_dist(21,1);
		
		if (dist_to_pc() <= 10)
			begIn_talk_mode(62);
			else begIn_talk_mode(63);
		}
		
	do_attack();
break;

beginstate TALKING_STATE;
	if (get_memory_cell(3) == 0) {
		print_str("Talking: You make a bit of small talk, but you don't learn");
		print_str("  anything interesting.");
		}
		else begin_talk_mode(get_memory_cell(3));
break;